package com.ideafactory.client.utils;

import android.text.TextUtils;

import org.json.JSONException;
import org.json.JSONObject;

public class TYTool {
    /**
     * 获取json 值
     * @param jsonObj jsonObejct
     * @param param 需要获取的参数
     * @param defVal 缺省值
     * @return Object
     */
    public static Object getJsonObj(JSONObject jsonObj, String param, Object defVal) {
        Object objValue ;
        try {
            objValue = jsonObj.get(param);
            if (objValue == null && defVal != null) {
                objValue = defVal;
            }
            if (objValue instanceof String) {
                if (TextUtils.isEmpty((String) objValue)) {
                    objValue = defVal;
                }
            }
        } catch (JSONException e) {
            objValue = defVal;
        }
        return objValue;
    }
}
